home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / mawk10.zip / DEPS.AWK < prev    next >
Text File  |  1991-10-05  |  1KB  |  58 lines

  1.  
  2. # find include dependencies in C source
  3. #
  4. # mawk -f deps.awk  C_source_files
  5. #         -- prints a dependency list suitable for make
  6. #         -- ignores   #include <   >
  7. #
  8.  
  9.  
  10. BEGIN {  stack_index = 0 # stack[] holds the input files
  11.  
  12.   for(i = 1 ; i < ARGC ; i++)
  13.   { 
  14.     file = ARGV[i]
  15.     if ( file !~ /\.c$/ )  continue  # skip it
  16.     outfile = substr(file, 1, length(file)-2) ".o"
  17.  
  18.     # INCLUDED[] stores the set of included files
  19.     # -- start with the empty set
  20.     for( j in INCLUDED ) delete INCLUDED[j]
  21.  
  22.     while ( 1 )
  23.     {
  24.         if ( getline line < file <= 0 )  # no open or EOF
  25.     { close(file)
  26.       if ( stack_index == 0 )  break # empty stack
  27.       else  
  28.       { file = stack[ stack_index-- ]
  29.         continue
  30.       }
  31.         }
  32.  
  33.     if ( line ~ /^#include[ \t]+".*"/ )
  34.     {
  35.       split(line, X, "\"")  # filename is in X[2]
  36.  
  37.       if ( X[2] in INCLUDED ) # we've already included it
  38.         continue
  39.  
  40.       #push current file 
  41.       stack[ ++stack_index ] = file
  42.       INCLUDED[ file = X[2] ] = ""
  43.         }
  44.     }  # end of while
  45.     
  46.    # test if INCLUDED is empty
  47.    flag = 0 # on once the front is printed 
  48.    for( j in INCLUDED )
  49.       if ( ! flag )  
  50.       { printf "%s : %s" , outfile, j ; flag = 1 }
  51.       else  printf " %s" , j
  52.  
  53.    if ( flag )  print ""
  54.  
  55.   }# end of loop over files in ARGV[i]
  56.  
  57. }
  58.